package com.zlzlib.libnetty.msg;


import com.zlzlib.libnetty.listener.NettyEvenListener;

/**
 * Created by zlz on 2019/11/18.
 * 消息转发器，负责将接收到的消息转发到应用层
 */
public class MsgDispatcher<T> {

    private NettyEvenListener<T> mOnEventListener;

    public MsgDispatcher() {
    }

    public void setOnEventListener(NettyEvenListener<T> listener) {
        this.mOnEventListener = listener;
    }

    /**
     * 接收消息，并通过OnEventListener转发消息到应用层
     *
     * @param msg 消息
     */
    public void receivedMsg(T msg) {
        if (mOnEventListener == null) {
            return;
        }
        mOnEventListener.dispatchMsg(msg);
    }
}
